#include "utils.h"
#include "graph.h"
#include <fstream>
#include <iostream>
#include <string>

#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <execinfo.h>

using namespace std;

void handler(int sig) {
	void *array[10];
  	size_t size;

	// get void*'s for all entries on the stack
  	size = backtrace(array, 10);

	// print out all the frames to stderr
  	// fprintf(stderr, "Error: signal %d:\n", sig);
	cerr << "Error: signal " << sig << ":" << endl;
	backtrace_symbols_fd(array, size, STDERR_FILENO);
  	exit(1);
}

int main(int argc, char* argv[]) {
	signal(SIGSEGV, handler);
	string name = string(argv[1]);
	vector<string> dt = readDataset(name);
	cout << dt[0] << endl;
	Graph g;
	Path path;
#ifdef LOG
	cout << "start reading" << endl;
#endif
	g.readDataset(dt);
	cout << "finish read" << endl;
	ofstream output;
	output.open(string(argv[1]) + "/result.fasta");
	for (int i = 0; i < 5; i++) {
		g.pathThreshold = 700;
		g.reset();
		cout << "第" << i << "个:" << endl;
		path = g.findLongestPath();
		output << path.toString() << endl;
	}
	return 0;
}
